'use strict';
const path = require('path');

module.exports = appInfo => {
  const config = {};

  // should change to your own
  config.keys = appInfo.name + '_1496992301237_4509';

  config.security = {
    csrf: {
      cookieName: 'csrfToken',
      headerName: 'X-CSRF-Token',
      bodyName: '_csrf',
      queryName: '_csrf',
      ignore: '/auth/token',
    },
  };

  config.static = {
    prefix: '/static/',
    dir: path.join(appInfo.baseDir, 'app/public/static'),
  };

  config.view = {
    defaultExt: '.html',
    mapping: {
      '.ejs': 'ejs',
      '.html': 'ejs',
    },
  };

  config.authConfig = {
    nodeTable: 'randy_auth_node',
    roleTable: 'randy_auth_role',
    roleUserTable: 'randy_auth_user_role',
    userTable: 'randy_auth_user'
  }

  config.knex = {
    // database configuration
    client: {
      // database dialect
      dialect: 'mysql',
      connection: {
        // host
        host: 'localhost',
        // 端口号
        port: '3306',
        // 用户名
        user: 'randylee',
        // 密码
        password: 'MDYwNzEy',
        // 数据库名
        database: 'dess_wx',
      },
      pool: { min: 0, max: 5 },
      acquireConnectionTimeout: 30000,
    },
    // load into app, default is open
    app: true,
    // load into agent, default is close
    agent: false,
  };

  config.redis = {
    clients: {
      session: {
        port: 6379,
        host: 'localhost',
        password: '060712',
        db: 0,
      },
      cache: {
        port: 6379,
        host: 'localhost',
        password: '060712',
        db: 1,
      },
    },
  };

  config.sessionRedis = {
    name: 'session',
  };

  config.oauth2Server = {
    grants: [ 'password' ],
    debug: appInfo.env === 'local',
  };
  
  config.checkLogin = {
    ignore: '/login',
  };

  config.checkAuth = {
    match: '/api',
  };

  return config;
};
